/**
 * @param {string} a
 * @param {string} b
 * @return {string}
 */
export var addBinary = function (a, b) {
  if (a.length < b.length) [a, b] = [b, a]
  b = b.padStart(a.length, '0')
  let [carry, ans] = [0, '']
  for (let i = 0; i < a.length; i++) {
    const sum = parseInt(a[a.length - 1 - i]) + parseInt(b[b.length - 1 - i]) + carry
    ans = (sum % 2) + ans
    carry = sum >> 1
  }
  if (carry) ans = carry + ans
  return ans
}
